package com.example.pwj.ffstudy.ui.fragment;

import com.blankj.utilcode.util.LogUtils;
import com.example.pwj.ffstudy.R;
import com.example.pwj.ffstudy.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pwj on 2017/8/22.
 */

public class DouFragment extends BaseFragment{
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_dou;
    }


    @Override
    protected void init() {
        List<Integer> integers = new ArrayList<>();
        for (int i = 0;i<50;i++) {
            integers.add(i);
        }
        Observable.just(integers)
                .flatMap(new Function<List<Integer>, ObservableSource<Integer>>() {
                    @Override
                    public ObservableSource<Integer> apply(@NonNull List<Integer> integers) throws Exception {
                        return Observable.fromIterable(integers);
                    }
                })
                .take(20)
                .takeLast(10)
                .toList()
                .subscribe(new Consumer<List<Integer>>() {
                    @Override
                    public void accept(@NonNull List<Integer> integers) throws Exception {
                        for (int i : integers) {
                            LogUtils.e("i:"+i);
                        }
                    }
                });

    }
}
